<template>
  <section class="zjhd-statistics-main">
    <div class="box-card">
      <el-row :gutter="20">
        <el-col>
          <div class="box-card-content">
            <span>待审核作品总数</span>
            <span class="din-front">{{ topInfo.neverCount || '0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>已审核作品总数</span>
            <span class="din-front">{{ topInfo.successCount || '0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>驳回作品总数</span>
            <span class="din-front">{{ topInfo.failCount || '0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>作品总数</span>
            <span class="din-front">{{ topInfo.worksCount || '0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>总访问量</span>
            <span class="din-front">{{ topInfo.pageview || '0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>总点赞数</span>
            <span class="din-front">{{ topInfo.favorNumber || '0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>获奖作品数</span>
            <span class="din-front">{{ topInfo.winningWorksNumber || '0' }}</span>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-collapse-transition>
      <section class="main-search separate">
        <section class="search-inner">
          <el-row>
            <el-col :span="12">
              <section class="search-inner-item">
                <div class="item-label">作品名称</div>
                <el-input
                  v-model.trim="search.worksName"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入作品名称搜索"
                />
              </section>
            </el-col>
            <el-col :span="12">
              <section class="search-inner-item">
                <div class="item-label">姓名</div>
                <el-input
                  v-model.trim="search.userName"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入姓名搜索"
                />
              </section>
            </el-col>
            <el-col :span="12">
              <div class="search-inner-item">
                <div class="item-label">证件号码</div>
                <el-input v-model.trim="search.idCard" style="width: 80%" class="filter-item" placeholder="请输入证件号码搜索" />
              </div>
            </el-col>
            <el-col :span="12">
              <div class="search-inner-item">
                <div class="item-label">手机号码</div>
                <el-input
                  v-model.trim="search.phoneNum"
                  style="width: 80%"
                  class="filter-item"
                  placeholder="请输入手机号码搜索"
                />
              </div>
            </el-col>

          </el-row>
        </section>
        <section class="search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
        </section>
      </section>
    </el-collapse-transition>

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>统计</span>
      </section>
      <section class="main-buttons-btns">
        <el-button style="margin-left: 10px" @click="exportFun">导出</el-button>
        <el-button style="margin-left: 10px" type="primary" @click="backFun">返回</el-button>
      </section>
    </section>
    <section class="main-table">
      <v-table
        :list="list"
        tag="worksStatistics"
        :selection="false"
        :source-arr="['worksCover']"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
      />
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </section>
  </section>
</template>
<script>
import {
  getTopInfo,
  queryPage,
  exportMask, exportNoMask
} from '../api/statistics'
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import CryptoJS from '@/utils/aesJiaJM'
import { exportSign } from '@/utils/fileImportOrExportSign'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'

export default {
  name: 'ZjhdStatistics',
  components: {
    VTable,
    Pagination
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10
      },
      search: {
        worksName: '',
        userName: '',
        phoneNum: '',
        idCard: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      topInfo: {},
      view: '/API-DOCUMENT/document/file/download?id='
    }
  },
  created() {
    if (this.$route.query) {
      this.query = this.$route.query
      this.getInfo()
      this.getList()
    } else {
      this.$message.error('页面参数错误')
      this.$router.back()
    }
  },
  methods: {
    backFun() {
      this.$router.back()
    },
    handleTabClick() {
      this.getList()
    },
    exportFun() {
      var query = exportSign({
        /* page: this.listQuery.page,
        pageSize: this.listQuery.limit,*/
        solicitationId: this.$route.query.ai,
        worksName: this.search.worksName,
        authorRealName: this.search.userName,
        authorPhoneNumber: this.search.phoneNum ? CryptoJS.$aesJiaM(this.search.phoneNum) : '',
        authorIdNumber: this.search.idCard ? CryptoJS.$aesJiaM(this.search.idCard) : ''
      }
      ).obj
      exportCheck('STAFF_SERVICE_SOLICITATION', this.$route.query.ai, exportMask, exportNoMask, query, '活动统计信息.xlsx')
    },
    filtercolumn(scope, item) {
      if (item === 'worksCover') {
        return this.view + scope.row[item]
      } else if (item === 'authorPhoneNumber' || item === 'authorIdNumber') {
        return scope.row[item] ? CryptoJS.$aesJieM(scope.row[item]) : '--'
      } else {
        return scope.row[item]
      }
    },
    handleReset() {
      this.listQuery.page = 1
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
      this.getInfo()
    },
    getInfo() {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        getTopInfo({
          id: this.$route.query.ai
        }).then(res => {
          loading.close()
          if (res.data.code === '200') {
            this.topInfo = res.data.data
          } else {
            this.$message.error(res.data.msg || '获取详情失败')
          }
        }).catch(error => {
          loading.close()
          reject(error)
        })
      })
    },
    getList(obj) {
      this.listLoading = true
      const query = {
        solicitationId: this.$route.query.ai,
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit
      }
      query['worksName'] = this.search.worksName
      query['authorRealName'] = this.search.userName
      query['authorPhoneNumber'] = CryptoJS.$aesJiaM(this.search.phoneNum)
      query['authorIdNumber'] = CryptoJS.$aesJiaM(this.search.idCard)
      return new Promise((resolve, reject) => {
        queryPage(query).then(response => {
          this.list = response.data.data.rows || []
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }
  }
}
</script>
<style lang="scss">
@import '@/styles/mixin.scss';

$dark_gray: #bfced6;

.zjhd-statistics-main {
  padding: 10px;

  .line {
    text-align: center;
  }

  .box-card {
    margin-bottom: 10px;
    text-align: center;
    background-color: #fff;
    padding: 20px;

    .el-col {
      width: 25% !important;

      .box-card-content {
        display: flex;
        flex-direction: column;
        justify-content: center;
        font-size: 16px;
        color: #666;
        border-radius: 8px;
        padding: 14px 0;
        margin-bottom: 15px;

        span:last-child {
          margin-top: 10px;
          font-size: 24px;
          font-weight: bold;
          line-height: 1;
        }
      }

      &:first-child .box-card-content {
        background: #fff2f1;

        span:last-child {
          color: #E44D42;
        }
      }

      &:nth-child(2) .box-card-content {
        background: #F3FAFF;

        span:last-child {
          color: #3EAAF9;
        }
      }

      &:nth-child(3) .box-card-content {
        background: #FFF8F1;

        span:last-child {
          color: #F08628;
        }
      }

      &:nth-child(4) .box-card-content {
        background: #F4FFE7;

        span:last-child {
          color: #82BC3C;
        }
      }

      &:nth-child(5) .box-card-content {
        background: #F8F5FF;

        span:last-child {
          color: #966AF9;
        }
      }

      &:nth-child(6) .box-card-content {
        background: #fff2f1;

        span:last-child {
          color: #E44D42;
        }
      }

      &:nth-child(7) .box-card-content {
        background: #F3FAFF;

        span:last-child {
          color: #3EAAF9;
        }
      }
    }

    .current-position-name {
      font-size: 18px;
      font-weight: bold;
      margin-bottom: 10px;
    }
  }

  .main-search {
    background-color: #fff;
    padding: 0 10px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            &.el-date-editor input {
              padding-left: 30px;
            }

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin: 10px 0;

    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);

      .num {
        @include font-color($mainColor);
      }
    }
  }
}
</style>
